package com.jason.happy.application.config;

import android.content.Context;

import com.facebook.cache.disk.DiskCacheConfig;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.jason.happy.common.utils.bitmap.ExternalUtil;

/**
 * Created by hacker on 17-6-26.
 */

public class ImageFrescoConfiguration {

    public static final String IMAGE_CACHE_BASE_NAME = "image_cache";


    /**
     * @param context
     */
    public static void initFresco(Context context) {
        ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context);
        builder.setMainDiskCacheConfig(createDiskCacheConfig(context));

        ImagePipelineConfig config = builder.build();
        Fresco.initialize(context, config);
    }

    /**
     * @param context
     * @return
     */
    public static DiskCacheConfig createDiskCacheConfig(Context context) {
        DiskCacheConfig.Builder builder = DiskCacheConfig.newBuilder(context);
        builder.setBaseDirectoryName(IMAGE_CACHE_BASE_NAME);
        builder.setBaseDirectoryPath(ExternalUtil.getAppCacheDir(context));
        return builder.build();
    }

}
